package com.aiobc.business.dataInfo.controller;

import java.io.IOException;
import java.util.List;

import com.aiobc.business.dataInfo.domain.DataApproval;
import com.aiobc.business.dataInfo.service.IDataApprovalService;
import com.aiobc.common.core.utils.poi.ExcelUtil;
import com.aiobc.common.core.web.controller.BaseController;
import com.aiobc.common.core.web.domain.AjaxResult;
import com.aiobc.common.core.web.page.TableDataInfo;
import com.aiobc.common.log.annotation.Log;
import com.aiobc.common.log.enums.BusinessType;
import com.aiobc.common.security.annotation.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import javax.servlet.http.HttpServletResponse;


/**
 * 数据审批Controller
 * 
 * @author xc
 * @date 2021-10-22
 */
@Controller
@RequestMapping("/dataApproval")
public class DataApprovalController extends BaseController
{

    @Autowired
    private IDataApprovalService dataApprovalService;

    /**
     * 查询数据审批列表
     */
    @PreAuthorize(hasPermi ="dataInfo:dataApproval:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(DataApproval dataApproval)
    {
        startPage();
        List<DataApproval> list = dataApprovalService.selectDataApprovalList(dataApproval);
        return getDataTable(list);
    }
    @PostMapping("/en")
    @ResponseBody
    public AjaxResult en()
    {
        return AjaxResult.success("ok");
    }

    /**
     * 导出数据审批列表
     */
    @PreAuthorize(hasPermi ="dataInfo:dataApproval:export")
    @Log(title = "数据审批", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public void export(HttpServletResponse respose, DataApproval dataApproval) throws IOException {
        List<DataApproval> list = dataApprovalService.selectDataApprovalList(dataApproval);
        ExcelUtil<DataApproval> util = new ExcelUtil<DataApproval>(DataApproval.class);
        util.exportExcel(respose,list, "数据审批数据");
    }


    /**
     * 新增保存数据审批
     */
    @PreAuthorize(hasPermi ="dataInfo:dataApproval:add")
    @Log(title = "数据审批", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(DataApproval dataApproval)
    {
        return toAjax(dataApprovalService.insertDataApproval(dataApproval));
    }

    /**
     * 修改数据审批
     */
    @GetMapping("/edit/{approvalId}")
    public String edit(@PathVariable("approvalId") String approvalId, ModelMap mmap)
    {
        DataApproval dataApproval = dataApprovalService.selectDataApprovalByApprovalId(approvalId);
        mmap.put("dataApproval", dataApproval);
        return "/edit";
    }

    /**
     * 修改保存数据审批
     */
    @PreAuthorize(hasPermi ="dataInfo:dataApproval:edit")
    @Log(title = "数据审批", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(DataApproval dataApproval)
    {
        return toAjax(dataApprovalService.updateDataApproval(dataApproval));
    }

    /**
     * 删除数据审批
     */
    @PreAuthorize(hasPermi ="dataInfo:dataApproval:remove")
    @Log(title = "数据审批", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(dataApprovalService.deleteDataApprovalByApprovalIds(ids));
    }
}
